package com.example.demo.Controller;

import com.example.demo.Dto.CreditDto;
import com.example.demo.Dto.CreditGetDto;
import com.example.demo.Service.CreditService;
import com.example.demo.VO.CreditVo;
import com.example.demo.result.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/credits")
public class CreditsController {
    @Autowired
    private CreditService creditService;
    /**
     * 添加银行卡
     * @param creditDto
     * @return
     */
    @PostMapping
    public ResponseResult pay(@RequestBody CreditDto creditDto) {
        CreditVo creditVo = creditService.saveCredit(creditDto);
        return new ResponseResult().ok(200,"银行卡添加成功",creditVo);
    }
    /**
     * 删除银行卡
     * @param id
     * @return
     */
    @DeleteMapping
    public ResponseResult delete(@RequestBody CreditGetDto id) {
       creditService.deletebyId( id);
        return new ResponseResult().ok(200,"银行卡删除成功",null);
    }
    /**
     * 获取银行卡
     * @return
     */
    @GetMapping("/{cardNumber}")
    public ResponseResult getAll(@PathVariable String cardNumber) {
        CreditVo credit = creditService.getCredit(cardNumber);
        return new ResponseResult().ok(200,"获取银行卡信息成功",credit);
    }
    /**
     * 获取某个用户所有银行卡信息
     * @return
     */
    @GetMapping
    public ResponseResult getAll(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        return new ResponseResult().ok(200,"获取银行卡列表成功",creditService.getCreditBysize(pageNum,pageSize));
    }
}
